using System;
using System.Collections.Generic;
using System.Linq;

namespace CodeDom
{
  /// <summary>
  /// Base type for item wrappers
  /// </summary>
  public class ItemProxy : IItem
  {
    /// <summary>
    /// Initializes a new instance of the <see cref="ItemProxy"/> class.
    /// </summary>
    /// <param name="item">The item.</param>
    internal ItemProxy(Item item)
    {
      Item = item;
    }

    /// <summary>
    /// Gets or sets the item.
    /// </summary>
    /// <value>The item.</value>
    protected Item Item { get; private set; }

    #region Implementation of IItem

    /// <summary>
    /// Gets the id of the parent item.
    /// </summary>
    /// <value>The parent id.</value>
    public Guid ParentId
    {
      get { return Item.ParentId; }
    }

    /// <summary>
    /// Gets the parent item, or null
    /// </summary>
    /// <value>The parent.</value>
    public Item Parent
    {
      get { return Item.Parent; }
    }

    public Guid ID
    {
      get { return Item.ID; }
    }

    /// <summary>
    /// Gets the name of the item
    /// </summary>
    /// <value>The name.</value>
    public string Name
    {
      get { return Item.Name; }
    }

    /// <summary>
    /// Returns the child items of the item
    /// </summary>
    /// <value>The children.</value>
    public IEnumerable<Item> Children
    {
      get { return Item.Children; }
    }

    /// <summary>
    /// Gets the template ID.
    /// </summary>
    /// <value>The template ID.</value>
    public Guid TemplateID
    {
      get { return Item.TemplateID; }
    }

    /// <summary>
    /// Gets the full item path.
    /// </summary>
    /// <value>The path.</value>
    public string Path
    {
      get { return Item.Path; }
    }

    /// <summary>
    /// Gets the template.
    /// </summary>
    /// <value>The template.</value>
    public Template Template
    {
      get { return Item.Template; }
    }

    /// <summary>
    /// Gets the fields on the item
    /// </summary>
    /// <value>The fields.</value>
    public IEnumerable<Field> Fields
    {
      get { return Item.Fields; }
    }

    /// <summary>
    /// Gets the value of a field by its ID
    /// </summary>
    /// <param name="id">The id.</param>
    /// <returns></returns>
    public Field GetField(Guid id)
    {
      return Item.GetField(id);
    }

    /// <summary>
    /// Gets the value of a named field
    /// </summary>
    /// <param name="fieldName">Name of the field.</param>
    /// <returns></returns>
    public Field GetField(string fieldName)
    {
      return Item.GetField(fieldName);
    }

    #endregion

    public bool Equals(IItem other)
    {
      return ID.Equals(other.ID);
    }

    public int CompareTo(IItem other)
    {
      return ID.CompareTo(other.ID);
    }
  }
}